//package com.xiaozhameng.study.bootrest.config;
//
//import com.zaxxer.hikari.HikariConfig;
//import com.zaxxer.hikari.HikariDataSource;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import javax.sql.DataSource;
//
///**
// * mysql配置 - 不起用
// */
//@Configuration
//@MapperScan(basePackages = "com.xiaozhameng.study.bootrest.compensatory.dao", sqlSessionFactoryRef = "sqlSessionFactory")
//public class DataSourceConfiguration {
//
//    /**
//     * 数据库连接池
//     */
//    @Bean(name = "dataSource")
//    public HikariDataSource dataSource() {
//        HikariConfig hikariConfig = new HikariConfig();
//        hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
//        hikariConfig.setUsername("root");
//        hikariConfig.setPassword("root");
//
//        // 最大连接数
//        hikariConfig.setMaximumPoolSize(10);
//        hikariConfig.setMinimumIdle(1);
//        hikariConfig.setJdbcUrl("jdbc:mysql://com.xiaozhameng.aliyun:3306/xiaozhameng?" +
//                "useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true");
//        return new HikariDataSource(hikariConfig);
//    }
//
//    /**
//     * 事物管理器
//     */
//    @Bean(name = "transactionManager")
//    @Primary
//    public DataSourceTransactionManager transactionManager() {
//        return new DataSourceTransactionManager(this.dataSource());
//    }
//
//    @Bean(name = "sqlSessionFactory")
//    @Primary
//    public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource dataSource) throws Exception {
//        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
//        sessionFactory.setDataSource(dataSource);
//        PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
//        sessionFactory.setMapperLocations(resourcePatternResolver.getResources("classpath*:spring/*.xml"));
//        return sessionFactory.getObject();
//    }
//}
